<template>
	<view class="content" style="margin-top: 30vh;">
		<div @click="go('userhome')">userhome</div>
		<div @click="go('usercenter')">usercenter</div>
		<div @click="go('record')">records</div>
		<div @click="getUserProfile">getUserProfile</div>
		<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取用户手机号</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keys: '',
				openid: ''
			}
		},
		onLoad() {},
		methods: {
			go(url) {
				uni.navigateTo({
					url: '/pages/' + url
				})
			},
			getUserProfile(e) {
				console.log('123')
				const that = this
				// 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
				// 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
				uni.getUserProfile({
					desc: '用于完善个人信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						console.log(res)
						if (res.errMsg == "getUserProfile:ok") {
							let userinfo = res.userInfo;
							let jmData = {
								encryptedData: res.encryptedData,
								iv: res.iv,
								rawData: res.rawData,
								siguature: res.siguature
							}
							return
							uni.login({
								success: (e) => {
									console.log(e)
									debugger
									uni.request({
										method: 'get',
										url: "https://www.zyts.cc/cmobile/index.php?app=borrowing_login&mod=xcx_login",
										data: {
											code: e.code,
											userinfo: userinfo,
											jmData: jmData
										},
										success: e => {
											console.log(e)
											const data = e.data.data.reinfo
											that.keys = data.keys
											that.openid = data.openid
										}
									})
								}
							})
						}
					}
				})
			},
			getPhoneNumber(e) {
				const that = this
				let phonedata, phonedataiv
				if (e.detail.errMsg !== 'getPhoneNumber:ok') return
				console.log(e)
				phonedata = e.detail.encryptedData;
				phonedataiv = e.detail.iv;
				uni.request({
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: 'post',
					url: 'https://www.zyts.cc/cmobile/index.php?app=borrowing_login&mod=gzh_auto_register_xcx',
					data: {
						phonedata: phonedata,
						phonedataiv: phonedataiv,
						client: 'wx_xcx',
						keys: that.keys
					},
					success: res => {
						console.log(res)
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.content>div {
		margin-top: 50px;
	}
</style>